home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / TokenMgrError.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  153 lines

  1. /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 0.7pre2 */
  2. /*
  3.  * @(#)TokenMgrError.java    1.5 98/03/12
  4.  * 
  5.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  6.  * 
  7.  * This software is the confidential and proprietary information of Sun
  8.  * Microsystems, Inc. ("Confidential Information").  You shall not
  9.  * disclose such Confidential Information and shall use it only in
  10.  * accordance with the terms of the license agreement you entered into
  11.  * with Sun.
  12.  * 
  13.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  14.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  15.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  16.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  17.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  18.  * THIS SOFTWARE OR ITS DERIVATIVES.
  19.  * 
  20.  */
  21. package com.sun.java.swing.text.html;
  22.  
  23. class TokenMgrError extends Error
  24. {
  25.    /*
  26.     * Ordinals for various reasons why an Error of this type can be thrown.
  27.     */
  28.  
  29.    /**
  30.     * Lexical error occured.
  31.     */
  32.    static final int LEXICAL_ERROR = 0;
  33.  
  34.    /**
  35.     * An attempt wass made to create a second instance of a static token manager.
  36.     */
  37.    static final int STATIC_LEXER_ERROR = 1;
  38.  
  39.    /**
  40.     * Tried to change to an invalid lexical state.
  41.     */
  42.    static final int INVALID_LEXICAL_STATE = 2;
  43.  
  44.    /**
  45.     * Detected (and bailed out of) an infinite loop in the token manager.
  46.     */
  47.    static final int LOOP_DETECTED = 3;
  48.  
  49.    /**
  50.     * Indicates the reason why the exception is thrown. It will have
  51.     * one of the above 4 values.
  52.     */
  53.    int errorCode;
  54.  
  55.    /**
  56.     * Replaces unprintable characters by their espaced (or unicode escaped)
  57.     * equivalents in the given string
  58.     */
  59.    protected static final String addEscapes(String str) {
  60.       StringBuffer retval = new StringBuffer();
  61.       char ch;
  62.       for (int i = 0; i < str.length(); i++) {
  63.         switch (str.charAt(i))
  64.         {
  65.            case 0 :
  66.               continue;
  67.            case '\b':
  68.               retval.append("\\b");
  69.               continue;
  70.            case '\t':
  71.               retval.append("\\t");
  72.               continue;
  73.            case '\n':
  74.               retval.append("\\n");
  75.               continue;
  76.            case '\f':
  77.               retval.append("\\f");
  78.               continue;
  79.            case '\r':
  80.               retval.append("\\r");
  81.               continue;
  82.            case '\"':
  83.               retval.append("\\\"");
  84.               continue;
  85.            case '\'':
  86.               retval.append("\\\'");
  87.               continue;
  88.            case '\\':
  89.               retval.append("\\\\");
  90.               continue;
  91.            default:
  92.               if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
  93.                  String s = "0000" + Integer.toString(ch, 16);
  94.                  retval.append("\\u" + s.substring(s.length() - 4, s.length()));
  95.               } else {
  96.                  retval.append(ch);
  97.               }
  98.               continue;
  99.         }
  100.       }
  101.       return retval.toString();
  102.    }
  103.  
  104.    /**
  105.     * Returns a detailed message for the Error when it is thrown by the
  106.     * token manager to indicate a lexical error.
  107.     * Parameters : 
  108.     *    EOFSeen     : indicates if EOF caused the lexicl error
  109.     *    curLexState : lexical state in which this error occured
  110.     *    errorLine   : line number when the error occured
  111.     *    errorColumn : column number when the error occured
  112.     *    errorAfter  : prefix that was seen before this error occured
  113.     *    curchar     : the offending character
  114.     * Note: You can customize the lexical error message by modifying this method.
  115.     */
  116.    private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
  117.       return("Lexical error at line " +
  118.            errorLine + ", column " +
  119.            errorColumn + ".  Encountered: " +
  120.            (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
  121.            "after : \"" + addEscapes(errorAfter) + "\"");
  122.    }
  123.  
  124.    /**
  125.     * You can also modify the body of this method to customize your error messages.
  126.     * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
  127.     * of end-users concern, so you can return something like : 
  128.     *
  129.     *     "Internal Error : Please file a bug report .... "
  130.     *
  131.     * from this method for such cases in the release version of your parser.
  132.     */
  133.    public String getMessage() {
  134.       return super.getMessage();
  135.    }
  136.  
  137.    /*
  138.     * Constructors of various flavors follow.
  139.     */
  140.  
  141.    public TokenMgrError() {
  142.    }
  143.  
  144.    public TokenMgrError(String message, int reason) {
  145.       super(message);
  146.       errorCode = reason;
  147.    }
  148.  
  149.    public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
  150.       this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
  151.    }
  152. }
  153.